import 'package:flutter/material.dart';
import 'base_layout.dart';

///
/// 列表部局
///
class ListLayout extends BaseLayout {
  //滚动方向,默认竖直
  final Axis scrollDirection;
  //列表控制器
  final ScrollController controller;
  //项目列表
  final List<Widget> children;
  //项目创建器，与项目列表只取其一
  final IndexedWidgetBuilder builder;
  //项目创建数量
  final int itemCount;

  ListLayout(
      {Key key,
      AlignmentGeometry alignment,
      double width,
      double height,
      bool isVisible,
      Decoration decoration,
      EdgeInsetsGeometry padding,
      EdgeInsetsGeometry margin,
      this.controller,
      this.scrollDirection = Axis.vertical,
      this.children = const [],
      this.builder,
      this.itemCount})
      : super(
            key: key,
            alignment: alignment,
            width: width,
            height: height,
            isVisible: isVisible,
            padding: padding,
            margin: margin,
            decoration: decoration);
  @override
  _ListLayoutState createState() => _ListLayoutState();
}

class _ListLayoutState extends State<ListLayout> with BaseState {
  @override
  void initState() {
    baseLayout = widget;
    super.initState();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }
  @override
  void didUpdateWidget(ListLayout oldWidget) {
    // TODO: implement didUpdateWidget
    super.didUpdateWidget(oldWidget);
  }
  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
  }
  @override
  Widget build(BuildContext context) {
    return buildState(buildContent);
  }
  @override
  buildContent() {
    return widget.builder == null
        ? ListView(
            scrollDirection: widget.scrollDirection,
            controller: widget.controller,
            children: widget.children,
            padding: widget.padding,
          )
        : ListView.builder(
          itemCount: widget.itemCount,
            itemBuilder: widget.builder,
            scrollDirection: widget.scrollDirection,
            controller: widget.controller,
            padding: widget.padding,
          );
  }
}
